﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Allan.Cards;

namespace CardGamesLibTest
{
    /// <summary>
    /// Tests the Card class.
    /// </summary>
    [TestClass]
    public class TestCard
    {
        public TestCard()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestBlackRed()
        {
            Card c = new Card(CardSuits.Clubs, CardValues.Ace);
            Assert.IsNotNull(c,"Card not initialized");
            Assert.IsTrue(c.IsBlack);
            Assert.IsFalse(c.IsRed);
            c = new Card(CardSuits.Diamonds, CardValues.Ace);
            Assert.IsNotNull(c);
            Assert.IsTrue(c.IsRed);
            Assert.IsFalse(c.IsBlack);
        }

        [TestMethod]
        public void TestEqual()
        {
            Card c = new Card(CardSuits.Diamonds, CardValues.Five);
            Card d = new Card(CardSuits.Diamonds, CardValues.Five);
            Card e = new Card(CardSuits.Diamonds, CardValues.Seven);
            Assert.IsTrue(c== d);
            Assert.IsTrue(c!= e);
        }

        [TestMethod]
        public void TestShortString()
        {
            Card c = new Card(CardSuits.Diamonds, CardValues.Seven);
            Assert.AreEqual<string>("7D", c.ToShortString());

        }

        [TestMethod]
        public void TestSerialize()
        {
            Card a = new Card(CardSuits.Clubs, CardValues.Ten);
            string s = a.Serialize();
            Assert.AreEqual("4A", s);
            Card b = Card.Deserialize(s);
            Assert.AreEqual(CardSuits.Clubs, b.Suit);
            Assert.AreEqual(CardValues.Ten, b.Value);
            Assert.IsTrue(a.Equals(b));
        }

        [TestMethod]
        public void TestOperator()
        {
            var j = new Card(CardSuits.Clubs, CardValues.Ten) + new Card(CardSuits.Clubs, CardValues.Queen);
            Assert.IsTrue(j is CardCollection);
        }

    }
}
